package com.ifighter.service.team;

import java.sql.SQLException;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class TeamService {

	private SQLiteDatabase db; 

	public TeamService(SQLiteDatabase db){
		this.db = db;
	}

	/**
	 * 
	 * @param sName
	 * @param sLastname
	 * @param sNickanme
	 * @param sPassword
	 * @param sEmail
	 * @return
	 */
	public long createNewUser(String sName, String sLastname, String sNickanme, String sPassword, String sEmail){

		ContentValues contentValues = new ContentValues();
		contentValues.put("NAME", sName);

		return db.insert(Team.TABLE, null, contentValues);
	}

	/**
	 * 
	 * @param sName
	 * @return
	 * @throws SQLException 
	 */
	public Team getTeamByName(String sName) throws SQLException{

		StringBuffer sql       = new StringBuffer();
		String[] selectionArgs = {sName};
		Cursor cursor          = null;
		Team result            = null;

		sql.append("SELECT * FROM ");
		sql.append(Team.TABLE);
		sql.append(" WHERE NAME = ?");

		cursor = this.db.rawQuery(sql.toString(), selectionArgs);

		if(cursor.moveToNext())
			result = new Team(cursor);

		return result;
	}	
}